package com.situ.hospital.service.impl;

import com.situ.hospital.dao.IMedicineDAO;
import com.situ.hospital.dao.IOrderDAO;
import com.situ.hospital.dao.IRestockingDAO;
import com.situ.hospital.dao.Impl.MedicineDAOImpl;
import com.situ.hospital.dao.Impl.OrderDAOImpl;
import com.situ.hospital.dao.Impl.RestockingDAOImpl;
import com.situ.hospital.pojo.Medicine;
import com.situ.hospital.pojo.Restocking;
import com.situ.hospital.pojo.vo.EarningsVO;
import com.situ.hospital.pojo.vo.MedicineIdVO;
import com.situ.hospital.service.IEchartsService;

import java.util.ArrayList;
import java.util.List;

public class EchartsServiceImpl implements IEchartsService {

    private IMedicineDAO medicineDAO = new MedicineDAOImpl();
    private IOrderDAO orderDAO = new OrderDAOImpl();
    private IRestockingDAO restockingDAO = new RestockingDAOImpl();

    @Override
    public List<EarningsVO> selectAll() {
        List<EarningsVO> list = new ArrayList<>();
        List<MedicineIdVO> medicineIdList = medicineDAO.selectIds();
        for (MedicineIdVO medicineId : medicineIdList) {
            Medicine medicine = medicineDAO.selectById(medicineId.getId());
            String name = medicine.getName();
            Integer number = orderDAO.selectByMedicineId(medicineId.getId());
            if (number == null) {
                number = 0;
            }
            double allSellPrice = number * medicine.getSellPrice();
            Restocking restocking = restockingDAO.selectByMedicineId(medicineId.getId());
            double allPurchasePrice = number * restocking.getPurchasePrice();
            double value = allSellPrice - allPurchasePrice;
            EarningsVO earningsVO = new EarningsVO(name,value);
            list.add(earningsVO);
        }
        return list;

       /* for(int medicine : medicineList) {
            Medicine medicine = medicineDAO.selectById(id);
            String name = medicine.getName();
            Integer number = orderDAO.selectByMedicineId(id);
            double allSellPrice = number * medicine.getSellPrice();
            Restocking restocking = restockingDAO.selectByMedicineId(id);
            double allPurchasePrice = number * restocking.getPurchasePrice();
            double value = allSellPrice - allPurchasePrice;
            EarningsVO earningsVO = new EarningsVO(name,value);
            list.add(earningsVO);
        }
        return list;*/
    }
}
